package com.yihu.wlyy.repository;

import com.yihu.wlyy.entity.patient.PatientDisease;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import java.util.List;

/**
 * 患者疾病Dao
 *
 * Created by lyr on 2016/09/09.
 */
public interface PatientDiseaseDao extends PagingAndSortingRepository<PatientDisease, Long>, JpaSpecificationExecutor<PatientDisease> {

    /**
     * 根据居民code获取居民疾病
     *
     * @param patient
     * @return
     */
    List<PatientDisease> findByPatient(String patient);

    /**
     * 根据居民code获取居民疾病
     *
     * @param patient
     * @return
     */
    @Query("select a from PatientDisease a where a.patient = ?1 and a.signType = '1' and a.del ='1' ")
    List<PatientDisease> findByPatientSsDisease(String patient);

    /**
     * 删除患者疾病
     *
     * @param patient
     * @return
     */
    int deleteByPatient(String patient);

    @Modifying
    @Query("update PatientDisease set del = '0' where patient = ?1 and del = '1' and signType = '2' ")
    int updateDiseaseDel(String patient);
}
